package cn.classTest.mall.service.impl;

import cn.classTest.mall.domain.Shop;
import cn.classTest.mall.mapper.ShopMapper;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.ShopService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;

    @Override
    public void saveOrUpdate(Shop shop) {
        if (shop.getId() == null) {
            shopMapper.save(shop);
        } else {
            shopMapper.update(shop);
        }

    }

    @Override
    public void delete(Long id) {
        shopMapper.delete(id);
    }

    @Override
    public Shop selectOne(Long id) {
        return shopMapper.selectOne(id);
    }

    @Override
    public List<Shop> selectAll() {
        return shopMapper.selectAll();
    }

    @Override
    public PageInfo<Shop> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Shop> shops = shopMapper.selectAll();

        PageInfo<Shop> pageInfo = new PageInfo<>(shops);

        return pageInfo;
    }
}
